package org.lcc.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;
import org.lcc.model.VO.CertificateTemplateVO;
import org.lcc.model.VO.CertificateTemplateFieldVO;
import org.lcc.model.entity.CertificateIssuance;

import java.util.List;
import java.util.Map;

@Mapper
public interface DashboardMapper {

    /**
     * 获取考试总数
     * @return 考试总数
     */
    @Select("SELECT COUNT(*) FROM exam")
    int getExamCount();

    /**
     * 获取考生总数
     * @return 考生总数
     */
    @Select("SELECT COUNT(*) FROM user WHERE role = 'student'")
    int getStudentCount();

    /**
     * 获取题库总量
     * @return 题库总量
     */
    @Select("SELECT COUNT(*) FROM question")
    int getQuestionCount();

    /**
     * 获取已完成考试数
     * @return 已完成考试数
     */
    @Select("SELECT COUNT(*) FROM exam WHERE status = '已结束'")
    int getCompletedExamCount();
    
    /**
     * 插入证书颁发记录
     * @param issuance 证书颁发记录
     * @return 影响行数
     */
    @Insert("INSERT INTO certificate_issuance(template_id, student_id, student_name, certificate_code, issuer, issue_date, content, status, create_time, exam_id,pdf_url) " +
            "VALUES(#{templateId}, #{studentId}, #{studentName}, #{certificateCode}, #{issuer}, #{issueDate}, #{content}, #{status}, #{createTime}, #{examId},#{pdfUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "issuanceId", keyColumn = "issuance_id")
    int insertCertificateIssuance(CertificateIssuance issuance);

    /**
     * 获取学生列表
     * @param examId 考试ID
     * @param passingScore 及格分数
     * @param keyword 搜索关键词
     * @return 学生列表
     */
    List<Map<String, Object>> getStudentsByExam(@Param("examId") Integer examId, 
                                               @Param("passingScore") Integer passingScore,
                                               @Param("keyword") String keyword);

    /**
     * 获取学生证书列表
     * @param studentId 学生ID
     * @param keyword 搜索关键词
     * @return 证书列表
     */
    List<Map<String, Object>> getStudentCertificates(@Param("studentId") String studentId, 
                                               @Param("keyword") String keyword);
}